package com.anytrek.demowebservice.controller;

import com.anytrek.demowebservice.entity.UserEntity;
import com.anytrek.demowebservice.utils.ApiResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class ApiController {

    @GetMapping
    public ApiResult getUserById(@RequestParam("id") Integer id) {
        UserEntity userEntity = UserEntity.getUserEntity(id);
        return ApiResult.success("获取成功", userEntity);
    }

    @PostMapping
    public ApiResult deleteUserByName(@RequestParam("name") String name) {
        UserEntity userEntity = UserEntity.getUserEntity(1);
        return ApiResult.success("删除成功",userEntity);
    }

    @GetMapping("/restful/{id}")
    public ApiResult getRestFulApi(@PathVariable("id") Integer id) {
        UserEntity userEntity = UserEntity.getUserEntity(id);
        return ApiResult.success("获取成功", userEntity);
    }

    @PostMapping("update")
    public ApiResult updateUser(@RequestBody UserEntity userEntity) {
        UserEntity user = UserEntity.getUserEntity(1);
        return ApiResult.success("更新成功",user);
    }
}